<template>
  <page-header-wrapper>
    <page-tab-list>
      <div class="table-page-search-box">
        <a-form layout="inline">
          <a-row :gutter="24">
            <a-col :md="8" :sm="24">
              <a-form-item label="商户">
                <a-input placeholder="请输入商户名称" v-model="queryParam.name" />
              </a-form-item>
            </a-col>
            <a-col :md="8" :sm="24">
              <a-form-item label="电话">
                <a-input placeholder="请输入商户电话" v-model="queryParam.tel" />
              </a-form-item>
            </a-col>
            <a-col :md="8" :sm="24">
              <a-form-item label="">
                <a-button type="primary" @click="getList">查询</a-button>
              </a-form-item>
            </a-col>
          </a-row>
        </a-form>
      </div>
    </page-tab-list>
    <a-card :bordered="false">
      <a-table
        :rowKey="
          (r, i) => {
            return r.id
          }
        "
        :pagination="{
          total: this.totalCount,
          showSizeChanger: false,
          onChange: this.tablePageChange
        }"
        :columns="columns"
        :data-source="list"
        :scroll="{ x: 'max-content' }"
      >
        <!-- <span slot="name" slot-scope="scope">
          {{ scope.info.info_name }}
        </span> -->
        <div slot="name" slot-scope="text">
          <div class="name">
            <div class="pic">
              <img :src="text.info.avatar_url" alt="" />
            </div>
            <div class="info">
              <span>{{ text.info.info_name }}</span>
            </div>
          </div>
        </div>

        <span slot="mobile" slot-scope="scope">
          {{ scope.info.tel }}
        </span>
        <span slot="type" slot-scope="text">
          {{ text == '0' ? '个人' : text == '1' ? '企业' : '个体工商户' }}
        </span>
        <span slot="before_price" slot-scope="text"> ￥{{ text || 0 }} </span>
        <span slot="after_price" slot-scope="text"> ￥{{ text || 0 }} </span>
        <span slot="addtime" slot-scope="text">
          {{ text > 0 ? $moment(text * 1000).format('YYYY-MM-DD HH:mm:ss') : '-' }}
        </span>
      </a-table>
    </a-card>
  </page-header-wrapper>
</template>

<script>
import { balanceRecord } from '@/api/purchase/purchase'
import tabList from '@/views/saas/components/tabList.vue'
import { cyyUploadImg } from '@/components/CyyUi'
const columns = [
  {
    title: 'ID',
    dataIndex: 'id',
    width: 80
  },
  {
    title: '商城信息',
    scopedSlots: {
      customRender: 'name'
    },
    width: 220
  },
  {
    title: '商户类型',
    dataIndex: 'type',
    scopedSlots: {
      customRender: 'type'
    }
  },
  {
    title: '手机号',
    scopedSlots: {
      customRender: 'mobile'
    }
  },
  {
    title: '变动前余额',
    dataIndex: 'before_price',
    scopedSlots: {
      customRender: 'before_price'
    },
    sorter: (a, b) => a.before_price - b.before_price
  },
  {
    title: '变动后余额',
    dataIndex: 'after_price',
    scopedSlots: {
      customRender: 'after_price'
    },
    sorter: (a, b) => a.after_price - b.after_price
  },
  {
    title: '详情',
    dataIndex: 'desc'
  },
  {
    title: '变更时间',
    dataIndex: 'addtime',
    sorter: (a, b) => a.addtime - b.addtime,
    scopedSlots: {
      customRender: 'addtime'
    }
  }
]

export default {
  components: {
    tabList,
    cyyUploadImg
  },
  data() {
    return {
      tabList: [
        {
          key: 'saasBusinessList',
          name: '商城列表'
        },
        // {
        //   key: 'saasBusinessBand',
        //   name: '绑定商品记录',
        // },
        {
          key: 'saasBusinessBalance',
          name: '余额记录'
        },
        {
          key: 'saasBusinessRecharge',
          name: '充值记录'
        }
        // {
        //     key:'saasBusinessTrans',
        //     name:'转单记录'
        // },
        // {
        //     key:'saasBusinessPurchase',
        //     name:'采购记录'
        // }
      ],
      // 搜索参数
      queryParam: {
        page: 1,
        limit: 10,
        tel: '',
        name: '',
        status: 1
      },
      selectedRowKeys: [],
      columns,
      list: [],
      totalCount: 0
    }
  },
  created() {
    this.getList()
  },
  methods: {
    // 分页请求
    tablePageChange(e) {
      this.queryParam.page = e
      this.getList()
    },
    // 获取数据
    async getList() {
      const hide = this.$message.loading('加载中...', 1000)
      const res = await balanceRecord(this.queryParam)
      if (res.code == 0) {
        this.list = res.data.list
        this.totalCount = res.data.count
      }
      hide()
    }
  }
}
</script>
<style lang="less" scoped>
.searchBox {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  /deep/ .ant-input-affix-wrapper {
    width: 220px;
    margin-right: 20px;
  }
  .select {
    margin-top: 11px;
    display: flex;
    align-items: center;
    margin-right: 15px;
  }
  .ant-btn {
    margin-top: 11px;
  }
}
.tip {
  line-height: normal;
  margin-bottom: 0;
  font-size: 14px;
  color: rgba(0, 0, 0, 0.45);
}

.name {
  display: flex;
  align-items: center;
  .pic {
    width: 48px;
    min-width: 48px;
    height: 48px;
    border-radius: 4px;
    overflow: hidden;
    margin-right: 24px;
    img {
      width: 100%;
      height: 100%;
    }
  }
  .info {
    flex: auto;
    width: 0;
    display: flex;
    flex-direction: column;
    font-size: 14px;
    span {
      width: 100%;
      overflow: hidden;
      white-space: nowrap;
      text-overflow: ellipsis;
    }
    span:nth-child(2) {
      color: rgba(0, 0, 0, 0.45);
      margin-top: 6px;
    }
  }
}
</style>
